Attribute VB_Name = "modHandleData"
Option Explicit

Public Sub HandleData(ByVal data As String)
    Dim parse() As String
    
    parse = Split(data, SEP_CHAR)
    
    Select Case LCase$(parse(0))
        
        Case "plainmessage"
            Call Packet_PlainMessage(parse(1))
            Exit Sub
        
        Case "userauthenticated"
            Call Packet_UserAuthenticated(parse(1))
            Exit Sub
            
        Case "news"
            Call Packet_News(parse(1), parse(2))
            Exit Sub
            
        Case "errormessage"
            Call Packet_ErrorMessage(parse(1))
            Exit Sub
            
    End Select
End Sub

'Only Prints Message
Public Sub Packet_PlainMessage(ByVal msg As String)
    Call MsgBox(msg, vbOKOnly, GAME_NAME)
End Sub

'if login succeeded
Public Sub Packet_UserAuthenticated(ByVal username As String)
    NameOfUser = username
    frmMainMenu.Hide
    Call Unload(frmLogin)
    frmGMain.Show
End Sub

'Client gets news from server
Public Sub Packet_News(ByVal title As String, news As String)
    Dim shownews, correctnews As String
    Dim newsarray As Variant
    Call Load(frmMainMenu)
    newsarray = Split(news, "``")
    correctnews = Join(newsarray, vbCrLf)
    shownews = title & vbCrLf & vbCrLf & correctnews
    If shownews <> frmMainMenu.txtShowNews.text Then
        frmMainMenu.txtShowNews.Refresh
        frmMainMenu.txtShowNews.text = shownews
    End If
End Sub

Public Sub Packet_ErrorMessage(ByVal errormsg As String)
    Call MsgBox(errormsg, vbCritical, GAME_NAME)
End Sub

